# -*-coding:utf-8 -*-
"""
指标的code对应的解释的名称输入至数据库中
"""
import config.base_info as cb
import pandas as pd
import common.sql as db
columns = ["index_type", "index_", "code_", "code_info",
           "index_type_info", "index_addr", "index_info"]


table_ = "intro_{0}"
temp_dict_ = dict()
def get_df_data():
    df = pd.DataFrame(columns=columns)
    for k, v in cb.INDEX_INFO.items():
        if k == "ctr":

            for k2, v2 in v['target'].items():
                temp_dict = temp_dict_.copy()
                for i3 in range(len(v2['return_data'])):
                    # print(v2['return_data_info'][i3])
                    temp_dict[columns[0]] = k
                    temp_dict[columns[1]] = k2
                    temp_dict[columns[2]] = v2['return_data'][i3]
                    temp_dict[columns[3]] = v2['return_data_info'][i3]
                    temp_dict[columns[4]] = v['info']
                    temp_dict[columns[5]] = v2['info_address']
                    temp_dict[columns[6]] = v2['info']
                    df=df.append(temp_dict, ignore_index=True )
    
    return df

# new_df=df.append(temp_dict, ignore_index=True)
if __name__ == '__main__':
    data=get_df_data()
    db.dataframe_tosql(data,table_.format("ctr"))
    # print(data.head(10))